<!--
 * @Author       : wfl
 * @LastEditors: ww
 * @description  :
 * @updateInfo   :
 * @Date         : 2022-11-23 15:19:53
 * @LastEditTime: 2023-06-30 17:40:42
-->
<script lang="ts" setup name="Node">
import ActionType from '@main/views/approve-workflow/WorkFlow/ActionType.vue'
import ellipsis from '@main/views/approve-workflow/WorkFlow/Ellipsis.vue'

const props = defineProps({
  // 是否为根节点
  isRoot: {
    type: Boolean,
    default: false
  },
  // 是否显示节点体
  show: {
    type: Boolean,
    default: true
  },
  // 节点内容区域文字
  content: {
    type: String,
    default: ''
  },
  title: {
    type: String,
    default: '标题'
  },
  placeholder: {
    type: String,
    default: '请设置'
  },
  // 节点体左侧图标
  leftIcon: {
    type: String,
    default: undefined
  },
  // 头部图标
  headerIcon: {
    type: String,
    default: ''
  },
  // 头部背景色
  headerBgc: {
    type: String,
    default: '#576a95'
  },
  // 是否显示错误状态
  showError: {
    type: Boolean,
    default: false
  },
  errorInfo: {
    type: String,
    default: '无信息'
  }
})

const emits = defineEmits<{
  (e: 'selected'): void
  (e: 'insertNode', val: string): void
  (e: 'delNode', node: any): void
}>()
const handSelected = () => {
  emits('selected')
}
const handInsertNode = (type: string) => {
  emits('insertNode', type)
}
const handDelNode = () => {
  emits('delNode', props.content)
}
</script>

<template>
  <div
    class="node"
    :class="{
      'root': isRoot || !show,
      'node-error-state': showError,
    }"
  >
    <div
      v-if="show"
      class="node-body trans-all-25"
      :class="{ error: showError }"
      @click="handSelected"
    >
      <div>
        <div
          class="node-body-header"
          :style="{ 'background-color': headerBgc }"
        >
          <div>
            <i
              v-if="(headerIcon || '') !== ''"
              :class="`ikflow ${headerIcon}`"
              style="margin-right: 5px;"
            ></i>
            <ellipsis class="name" hover-tip :content="title" />
          </div>
          <i
            v-show="!isRoot"
            class="ikflow ikflow-guanbi trans-all-25"
            style="float: right;"
            @click.self.stop="handDelNode"
          ></i>
        </div>
        <div class="node-body-content">
          <i v-if="leftIcon" :class="leftIcon"></i>
          <span v-if="(content || '').trim() === ''" class="placeholder">{{
            placeholder
          }}</span>
          <ellipsis v-else :row="3" :content="content" />
          <i class="el-icon-arrow-right"></i>
        </div>
        <div v-if="showError" class="node-error">
          <el-tooltip effect="dark" :content="errorInfo" placement="top-start">
            <i class="el-icon-warning-outline"></i>
          </el-tooltip>
        </div>
      </div>
    </div>
    <div class="node-footer">
      <div class="btn">
        <ActionType @insertNode="handInsertNode" />
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.root {
  &::before {
    display: none !important;
  }
}

.node-error-state {
  .node-body {
    box-shadow: 0 0 5px 0 #f56c6c !important;
  }
}

.node {
  width: var(--node-width);
  position: relative;
  user-select: none;

  &::before {
    content: '';
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    border-style: solid;
    border-width: 8px 6px 4px;
    border-color: var(--el-text-color-disabled) transparent transparent;
    background: var(--ik-page-bg);
  }

  .node-body {
    cursor: pointer;
    max-height: 120px;
    position: relative;
    border-radius: 5px;
    background-color: var(--el-bg-color);
    box-shadow: var(--el-box-shadow-light);

    &:hover {
      box-shadow: 0 0 3px 0 var(--theme-primary);

      .node-body-header {
        .ikflow-guanbi {
          font-size: 14px;
          opacity: 1;
        }
      }
    }

    .node-body-header {
      border-top-left-radius: 5px;
      border-top-right-radius: 5px;
      padding: 8px 15px;
      color: white;
      font-size: xx-small;
      display: flex;
      align-items: center;
      justify-content: space-between;

      & > div {
        display: flex;
        align-items: center;
      }

      .ikflow-guanbi {
        font-size: 14px;
        opacity: 0;
      }

      .name {
        // height: 14px;
        width: 150px;
        display: inline-block;
      }
    }

    .node-body-content {
      padding: 18px;
      color: var(--ik-pagin-text-color);
      font-size: 14px;

      i {
        position: absolute;
        top: 55%;
        right: 5px;
        font-size: 14px;
      }

      .placeholder {
        color: var(--ik-pagin-text-color);
      }
    }

    .node-error {
      position: absolute;
      right: -40px;
      top: 20px;
      font-size: 25px;
      color: #f56c6c;
    }
  }

  .node-footer {
    position: relative;

    .btn {
      width: 100%;
      display: flex;
      padding: 32px 0;
      justify-content: center;
    }

    :deep(.el-button) {
      height: 32px;
      width: 32px;
    }

    &::before {
      content: '';
      position: absolute;
      inset: 0;
      z-index: -1;
      margin: auto;
      width: 2px;
      height: 100%;
      background-color: var(--el-text-color-disabled);
    }
  }
}
</style>
